import 'package:flutter/material.dart';
import 'package:flutterroom/pages/home/tab_search/dataList.dart';
import 'package:flutterroom/pages/my/widget/my_add_room_title.dart';

class RightDrawer extends StatefulWidget {
  @override
  _RightDrawerState createState() => _RightDrawerState();
}

class _RightDrawerState extends State<RightDrawer> {
  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: SafeArea(
          child: ListView(
        children: <Widget>[
          AddRoomTitle(
            title: "户型",
          ),
          RightDrawerItem(
            list: roomTypeList,
            selectedIds: ["77"],
          ),
          AddRoomTitle(
            title: "朝向",
          ),
          RightDrawerItem(
            list: orientedList,
            selectedIds: ["99"],
          ),
          AddRoomTitle(
            title: "楼层",
          ),
          RightDrawerItem(
            list: floorList,
            selectedIds: ["dd"],
          ),
        ],
      )),
    );
  }
}

class RightDrawerItem extends StatelessWidget {
  final List<GeneralType> list;
  final List<String> selectedIds;
  final ValueChanged<String> onChange;

  const RightDrawerItem({Key key, this.list, this.selectedIds, this.onChange})
      : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(left: 10, right: 10, top: 4, bottom: 6),
      child: Wrap(
          spacing: 8.0,
          children: list.map((e) {
             var isSele = selectedIds.contains(e.id);
            return GestureDetector(
              onTap: () {
                if (onChange != null) {
                  onChange(e.id);
                }
              },
              behavior: HitTestBehavior.translucent,
              child: Container(
                width: 100,
                height: 40,
                decoration: BoxDecoration(
                  color: isSele? Colors.white:Colors.green,
                    border: Border.all(width: 1, color: Colors.green)),
                child: Center(
                  child: Text(e.name,style:TextStyle(color: isSele ? Colors.green : Colors.white,)),
                ),
              ),
            );
          }).toList()),
    );
  }
}
